<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>会员管理
            <small>体检上传</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>会员管理</el-breadcrumb-item>
            <el-breadcrumb-item>体检上传</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!--v-model="pagination.queryString" 双向绑定了 下面pagination.queryString变量-->
                <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button @click="findPageWithInfo()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">新增</el-button>
                <el-button style="margin-bottom: 10px;margin-left: 10px" type="primary" @click="downloadTemplate()">模板下载</el-button>
                <span>
                    提示:请点击"模板下载"按钮获取模板文件
                </span>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>

                <el-table-column type="index" align="center" label="序号"></el-table-column>

                <el-table-column prop="physicalTime" label="体检时间" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                </el-table-column>
                <!--<el-table-column prop="phoneNumber"  label="手机号码" align="center"></el-table-column>-->
                <!--<el-table-column prop="setMealName"  label="检测套餐" align="center"></el-table-column>-->
                <el-table-column prop="reportStatus" label="报告状态" align="center">
                    <template slot-scope="scope">
                        <span>{{ scope.row.reportStatus == 'null' ? '未提交' : scope.row.reportStatus == '0' ? '未提交' : '已提交'}}</span>
                    </template>
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpload(scope.row)">上传报告</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <!--为分页条组件绑定current-change事件，此事件是分页条组件自己定义的事件，当页码改变时触发，对
                    应的处理函数为handleCurrentChang-->
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>
            <!-- 新增窗口内容 -->
            <div class="add-form">
                <el-dialog title="新增会员" :visible.sync="dialogFormVisible">
                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right"
                             label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input v-model="formData.name"/>
                                </el-form-item>
                            </el-col>

                            <el-col :span="12">
                                <el-form-item label="档案号" prop="fileNumber">
                                    <el-input v-model="formData.fileNumber"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="体检时间"  prop="physicalTime">
                                    <el-input placeholder="范例:20191207" v-model="formData.physicalTime"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="报告状态" prop="reportStatus">
                                    <el-input placeholder="请输入(0:未上传;1:已上传)" v-model="formData.reportStatus"/>
                                    <template slot-scope="scope">
                                        <span>{{ scope.row.reportStatus == 'null' ? '未提交' : scope.row.reportStatus == '0' ? '未提交' : '已提交'}}</span>
                                    </template>
                                </el-form-item>
                            </el-col >
                            <el-upload
                                    action="/physicalUpload/upload.do"
                                    :auto-upload="autoUpload"
                                    name="excelFile"
                                    :show-file-list="false"
                                    :on-success="handleSuccess"
                                    :before-upload="beforeUpload">
                                <el-button style="margin-bottom: 10px;margin-left: 10px" slot="trigger" size="medium" type="primary">选取文件</el-button>
                                <div slot="tip" class="el-upload__tip">上传文件只能是xls或者xlsx格式</div>
                            </el-upload>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                    </el-form>
                </el-dialog>
            </div>


            <!-- 上传报告 -->
            <div class="add-form">
                <el-dialog title="上传报告" :visible.sync="dialogFormVisible4Edit">
                    <el-form ref="dataUploadForm" :model="formData" label-position="right" label-width="100px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="姓名" prop="name">
                                    <el-input readonly="readonly" v-model="formData.name"/>
                                </el-form-item>
                            </el-col>

                            <el-col :span="12">
                                <el-form-item label="档案号" prop="fileNumber">
                                    <el-input readonly="readonly" v-model="formData.fileNumber"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="体检时间" prop="physicalTime">
                                    <el-input readonly="readonly" v-model="formData.physicalTime"/>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="报告状态" prop="reportStatus">
                                    <el-input readonly="readonly"  v-model="formData.reportStatus"/>
                                </el-form-item>
                            </el-col >
                            <el-upload
                                    action="/physicalUpload/edit.do"
                                    :auto-upload="autoUpload"
                                    name="excelFile"
                                    :show-file-list="false"
                                    :on-success="handleSuccess"
                                    :before-upload="beforeUpload">
                                <el-button style="margin-bottom: 10px;margin-left: 10px" slot="trigger" size="medium" type="primary">选取文件</el-button>
                                <div slot="tip" class="el-upload__tip">上传文件只能是xls或者xlsx格式</div>
                            </el-upload>
                        </el-row>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button  @click="dialogFormVisible4Edit = false">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            autoUpload:true,//自动上传
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
                /* queryString:null//查询条件 双向绑定了  输入框的内容*/
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//编辑表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            rules: {//校验规则
                name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                fileNumber: [{required: true, message: '档案号为必填项', trigger: 'blur'}],
                physicalTime: [{required: true, message: '体检时间为必填项', trigger: 'blur'}],
                reportStatus: [{required: true, message: '报告状态为必填项', trigger: 'blur'}]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();  //每次弹出新增表单的时候 清空表单数据
                this.dialogFormVisible = true;  //点击新增按钮 触发该方法,让新增表单显示
            },
            //  验证后提交新增表单
            handleAdd() {
                this.$refs["dataAddForm"].validate((valid) => {
                    if (valid) {
                        axios.post("/physicalUpload/addMember.do",this.formData).then((res)=>{
                            if (res.data.flag){
                                //新增成功
                                this.$message({
                                    message:res.data.message,
                                    type:"success"
                                })
                            } else {
                                //新增失败
                                this.$message.error(res.data.message)
                            }
                        }).finally(()=>{
                            this.dialogFormVisible=false;
                            this.findPage();
                        })
                    }
                })
            },
            // 模板下载
            downloadTemplate(){
                window.location.href="../../template/dataFile.xlsx";
            },
            //上传成功提示
            handleSuccess(response, file) {
                //根据上传成功的返回 进行判断并且提示

                this.$message({
                    message:response.message,
                    type:response.flag?'success':'error'
                })
                this.findPage();
            },
            //上传之前进行文件格式校验
            beforeUpload(file){
                const isXLS = file.type === 'application/vnd.ms-excel';
                if(isXLS){
                    return true;
                }
                const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                if (isXLSX) {
                    return true;
                }
                this.$message.error('上传文件只能是xls或者xlsx格式!');
                return false;
            },
            //查询功能
            findPageWithInfo() {
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //分页查询
            findPage() {
                var param = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                //页面一加载就调用分页查询 ,分页查询发送ajax请求去获取数据
                axios.post("/physicalUpload/findPage.do", param).then((res) => {
                    //res为后台回写过来的数据json对象
                    // res.data.rows 是拿到返回的数据的所有内容
                    if (res.data.total == 0) {
                        this.$message.error("未找到相关检查项");
                    }
                    this.dataList = res.data.rows;//将所有内容给双向绑定的dataList变量
                    this.pagination.total = res.data.total;//查询到的总页数给前台展示
                })
            },
            //切换页码,currentPage为切换后的页码!
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                //修改当前页以后,每页显示的条数不变 继续进行分页查询
                this.findPage();
            },

            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 点击操作,上传报告:弹出回显表格
            handleUpload(row) {
                axios.get("/physicalUpload/findMemberById.do?id=" + row.id).then((res) => {
                    if (res.data.flag) {
                        //当找到信息以后 弹出修改框
                        this.dialogFormVisible4Edit = true;
                        this.formData = res.data.data;
                        res.data.data.reportStatus=='null' ? this.formData.reportStatus='未提交' :res.data.data.reportStatus=== '0' ?this.formData.reportStatus= '未提交' : this.formData.reportStatus='已提交';
                        this.$message({
                            message: res.data.message,
                            type: "success"
                        })
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
            },
            // 删除当前行id
            handleDelete(row) {
                this.$confirm('此操作将永久删除该会员的数据文件,是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/physicalUpload/deleteMember.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                message: res.data.message,
                                type: 'success'
                            });
                            this.findPage();
                        } else {
                            this.$message.error(res.data.message)
                        }
                    })
                })
            }
        }
    })
</script>
</html>